package de.pasbreuer.openmovieman;

import java.util.HashMap;

public class EntityManagement {
	private static HashMap<Integer,Entity> entities = new HashMap<Integer,Entity> ();
	private static char currency = '€';
	
	public static char getCurrency() {
		return currency;
	}

	public static void setCurrency(char incurrency) {
		currency = incurrency;
	}

	public static void saveEntity(Entity e){
		if (entities.get(e.getId()) == null){
			entities.put(e.getId(), e);
		}
		else{
			System.err.println("ID already exists");
		}
	}
	
	public static HashMap<Integer,Entity> getHashMap(){
		return entities;
	}
	
	public static Entity[] toArray(){
		return entities.values().toArray(new Entity[entities.size()]);
	}
	
	public static String[][] toStringArray(){
		String result[][]= new String[entities.size()][Entity.columnNames.length];
		int i = 0;
		for (Entity value : entities.values()) {
			result[i][0] = ""+value.getId();
			result[i][2] = ""+value.getTitle();
			result[i][3] = ""+value.getLocation();
			result[i][4] = ""+value.getPurchaseDate();
			result[i][5] = ""+value.getPurchasePrice() + " " + currency;
			if (value instanceof DVD){
				result[i][1] = "DVD";
			}
			else if (value instanceof BluRay){
				result[i][1] = "Blu-Ray";
			}
			else if (value instanceof VHS){
				result[i][1] = "VHS";
			}
			else{
				result[i][1] = "";
			}
			i++;
		}
		return result;
	}
	
}
